/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LoginPanel.java
 *
 * Created on 2010-9-25, 16:43:50
 */

package finalsoft;


import Sql.*;
import org.jdesktop.application.Action;
import javax.swing.*;
/**
 *
 * @author lq
 */
public class LoginPanel extends javax.swing.JPanel{

    /** Creates new form LoginPanel */
    public LoginPanel() {
        initComponents();
    }

    public LoginPanel(java.awt.image.BufferedImage image){
        this.image = image ;
        initComponents();
    }
    @Override
    protected   void   paintComponent(java.awt.Graphics   g)   {
        g.drawImage(image,   0,   0,   this.getWidth(),   this.getHeight(),   this);
     }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLoginPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jUserNameTextField = new javax.swing.JTextField();
        jUserPasswordField = new javax.swing.JPasswordField();
        jLoginButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jSaveUserBox = new javax.swing.JCheckBox();
        jAutoLoginBox = new javax.swing.JCheckBox();
        jImageLabel = new javax.swing.JLabel();
        jCheckCodeTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLoginerInfoPanel = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jGetUserNameLabel = new javax.swing.JLabel();
        jGetLevelLabel = new javax.swing.JLabel();
        jGetAddressLabel = new javax.swing.JLabel();
        jGetEmailLabel = new javax.swing.JLabel();
        jGetTelLabel = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jGetLastLoginLable = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(finalsoft.FinalSoftApp.class).getContext().getResourceMap(LoginPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(800, 600));

        jLoginPanel.setBackground(resourceMap.getColor("jLoginPanel.background")); // NOI18N
        jLoginPanel.setName("jLoginPanel"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jUserNameTextField.setText(resourceMap.getString("jUserNameTextField.text")); // NOI18N
        XMLParse xml = new XMLParse();
        String [] str = xml.checkXML();
        if(str != null){
            jUserNameTextField.setText(str[0]);
        }
        jUserNameTextField.setName("jUserNameTextField"); // NOI18N

        jUserPasswordField.setText(resourceMap.getString("jUserPasswordField.text")); // NOI18N
        if(str != null){
            jUserPasswordField.setText(str[1]);
        }
        jUserPasswordField.setName("jUserPasswordField"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(finalsoft.FinalSoftApp.class).getContext().getActionMap(LoginPanel.class, this);
        jLoginButton.setAction(actionMap.get("UserLogin")); // NOI18N
        jLoginButton.setText(resourceMap.getString("jLoginButton.text")); // NOI18N
        jLoginButton.setName("jLoginButton"); // NOI18N

        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCancelButtonMouseClicked(evt);
            }
        });

        jSaveUserBox.setText(resourceMap.getString("jSaveUserBox.text")); // NOI18N
        jSaveUserBox.setName("jSaveUserBox"); // NOI18N
        jSaveUserBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSaveUserBoxStateChanged(evt);
            }
        });
        jSaveUserBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jSaveUserBoxItemStateChanged(evt);
            }
        });

        jAutoLoginBox.setText(resourceMap.getString("jAutoLoginBox.text")); // NOI18N
        jAutoLoginBox.setName("jAutoLoginBox"); // NOI18N
        jAutoLoginBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jAutoLoginBoxItemStateChanged(evt);
            }
        });

        jImageLabel.setBackground(resourceMap.getColor("jImageLabel.background")); // NOI18N
        jImageLabel.setForeground(resourceMap.getColor("jImageLabel.foreground")); // NOI18N
        jImageLabel.setText(resourceMap.getString("jImageLabel.text")); // NOI18N
        jImageLabel.setName("jImageLabel"); // NOI18N
        showCheckImage();
        jImageLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jImageLabelMouseClicked(evt);
            }
        });

        jCheckCodeTextField.setText(resourceMap.getString("jCheckCodeTextField.text")); // NOI18N
        jCheckCodeTextField.setName("jCheckCodeTextField"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jLoginPanelLayout = new javax.swing.GroupLayout(jLoginPanel);
        jLoginPanel.setLayout(jLoginPanelLayout);
        jLoginPanelLayout.setHorizontalGroup(
            jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginPanelLayout.createSequentialGroup()
                .addGap(186, 186, 186)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(148, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLoginPanelLayout.createSequentialGroup()
                .addGap(227, 227, 227)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jLoginPanelLayout.createSequentialGroup()
                            .addComponent(jLoginButton)
                            .addGap(78, 78, 78)
                            .addComponent(jCancelButton))
                        .addComponent(jUserNameTextField, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jUserPasswordField, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jLoginPanelLayout.createSequentialGroup()
                            .addComponent(jSaveUserBox)
                            .addGap(18, 18, 18)
                            .addComponent(jAutoLoginBox)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLoginPanelLayout.createSequentialGroup()
                        .addComponent(jCheckCodeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
                        .addGap(48, 48, 48)
                        .addComponent(jImageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(268, 268, 268))
        );
        jLoginPanelLayout.setVerticalGroup(
            jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginPanelLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel1)
                .addGap(58, 58, 58)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jUserNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(34, 34, 34)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jUserPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(10, 10, 10)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckCodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jImageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSaveUserBox)
                    .addComponent(jAutoLoginBox))
                .addGap(30, 30, 30)
                .addGroup(jLoginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLoginButton)
                    .addComponent(jCancelButton))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        if(str[0] != ""){
            jSaveUserBox.setSelected(true);
        }
        if(str[1] != ""){
            jAutoLoginBox.setSelected(true);
        }

        jLoginerInfoPanel.setSize(776, 482);
        jLoginerInfoPanel.setLocation(10, 10);
        jLoginerInfoPanel.setBackground(resourceMap.getColor("jLoginerInfoPanel.background")); // NOI18N
        jLoginerInfoPanel.setEnabled(false);
        jLoginerInfoPanel.setName("jLoginerInfoPanel"); // NOI18N
        jLoginerInfoPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jLoginerInfoPanelComponentShown(evt);
            }
        });

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jGetUserNameLabel.setFont(resourceMap.getFont("jGetUserNameLabel.font")); // NOI18N
        jGetUserNameLabel.setText(resourceMap.getString("jGetUserNameLabel.text")); // NOI18N
        jGetUserNameLabel.setName("jGetUserNameLabel"); // NOI18N

        jGetLevelLabel.setFont(resourceMap.getFont("jGetLevelLabel.font")); // NOI18N
        jGetLevelLabel.setText(resourceMap.getString("jGetLevelLabel.text")); // NOI18N
        jGetLevelLabel.setName("jGetLevelLabel"); // NOI18N

        jGetAddressLabel.setFont(resourceMap.getFont("jGetAddressLabel.font")); // NOI18N
        jGetAddressLabel.setText(resourceMap.getString("jGetAddressLabel.text")); // NOI18N
        jGetAddressLabel.setName("jGetAddressLabel"); // NOI18N

        jGetEmailLabel.setFont(resourceMap.getFont("jGetEmailLabel.font")); // NOI18N
        jGetEmailLabel.setText(resourceMap.getString("jGetEmailLabel.text")); // NOI18N
        jGetEmailLabel.setName("jGetEmailLabel"); // NOI18N

        jGetTelLabel.setFont(resourceMap.getFont("jGetTelLabel.font")); // NOI18N
        jGetTelLabel.setText(resourceMap.getString("jGetTelLabel.text")); // NOI18N
        jGetTelLabel.setName("jGetTelLabel"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jGetLastLoginLable.setFont(resourceMap.getFont("jGetLastLoginLable.font")); // NOI18N
        jGetLastLoginLable.setText(resourceMap.getString("jGetLastLoginLable.text")); // NOI18N
        jGetLastLoginLable.setName("jGetLastLoginLable"); // NOI18N

        javax.swing.GroupLayout jLoginerInfoPanelLayout = new javax.swing.GroupLayout(jLoginerInfoPanel);
        jLoginerInfoPanel.setLayout(jLoginerInfoPanelLayout);
        jLoginerInfoPanelLayout.setHorizontalGroup(
            jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginerInfoPanelLayout.createSequentialGroup()
                .addGap(104, 104, 104)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(100, 100, 100)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jGetAddressLabel)
                    .addComponent(jGetLevelLabel)
                    .addComponent(jGetEmailLabel)
                    .addComponent(jGetUserNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jLoginerInfoPanelLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jGetLastLoginLable)
                            .addComponent(jGetTelLabel))))
                .addContainerGap(281, Short.MAX_VALUE))
        );
        jLoginerInfoPanelLayout.setVerticalGroup(
            jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginerInfoPanelLayout.createSequentialGroup()
                .addGap(72, 72, 72)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jGetUserNameLabel))
                .addGap(33, 33, 33)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jGetLevelLabel))
                .addGap(35, 35, 35)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jGetAddressLabel))
                .addGap(33, 33, 33)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jGetEmailLabel))
                .addGap(38, 38, 38)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jGetTelLabel))
                .addGap(28, 28, 28)
                .addGroup(jLoginerInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jGetLastLoginLable))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(jLoginPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(jLoginerInfoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(73, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLoginPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(158, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(jLoginerInfoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(124, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jLoginerInfoPanelComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jLoginerInfoPanelComponentShown
        // TODO add your handling code here:
        jGetUserNameLabel.setText(user.getUname());
        jGetLevelLabel.setText(user.getLevelname());
        jGetAddressLabel.setText(user.getAddress());
        jGetEmailLabel.setText(user.getEmail());
        jGetTelLabel.setText(user.getTel());
        jGetLastLoginLable.setText(user.getLastlogin().toString());
        
    }//GEN-LAST:event_jLoginerInfoPanelComponentShown

    private void jSaveUserBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSaveUserBoxStateChanged
        // TODO add your handling code here:
}//GEN-LAST:event_jSaveUserBoxStateChanged

    private void jSaveUserBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jSaveUserBoxItemStateChanged
      if(evt.getStateChange() == evt.SELECTED){
            saveuid = 1;
        }else{
            saveuid = 0;
            jAutoLoginBox.setSelected(false);
        }
}//GEN-LAST:event_jSaveUserBoxItemStateChanged

    private void jCancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCancelButtonMouseClicked
        // TODO add your handling code here:
        jUserNameTextField.setText("");         //   当点击取消按钮的时候 清除用户名框和密码框的内容
        jUserPasswordField.setText("");
    }//GEN-LAST:event_jCancelButtonMouseClicked

    private void jAutoLoginBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jAutoLoginBoxItemStateChanged
        if(evt.getStateChange() == evt.SELECTED){
            savepassword = 1;
            jSaveUserBox.setSelected(true);
        }else{
            savepassword = 0;
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jAutoLoginBoxItemStateChanged

    private void jImageLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jImageLabelMouseClicked

        showCheckImage();

    }//GEN-LAST:event_jImageLabelMouseClicked


    // 点 “登录” 按钮所执行的操作
    @Action
    public void UserLogin() {
        if( ((this.code).toLowerCase()).equals((jCheckCodeTextField.getText()).toLowerCase()) ){
            JOptionPane.showMessageDialog(null, "验证码错误！ "+ this.code , "登录失败", JOptionPane.ERROR_MESSAGE);
        }else{

            try{
                String  username ;
                String userpassword ;
                MainFrame MP = new MainFrame() ;

                username = jUserNameTextField.getText() ;
                userpassword = new String( jUserPasswordField.getPassword() ) ;//将用户密码转换成string类型

                /************************************************/
               // 这是处理 记住用户名 记住密码 功能的代码
                XMLParse xml = new XMLParse();
                if(saveuid == 1 && savepassword == 0){
                    xml.updateXML();
                    xml.updateXML(username);
                }
                else if(saveuid == 0 && savepassword == 0){
                    xml.updateXML();
                }
                else if(saveuid == 1 && savepassword == 1){
                     xml.updateXML(username,userpassword);
                }else{
                    xml.updateXML();
                }
                /************************************************/

                Mysql mysql = new Mysql();

                jLoginerInfoPanel.setVisible(false); //先将jLoginerInfoPanel面板设为不可见   当登陆后变为可见
                 //创建一个事件监听jLoginerInfoPanelComponentShown来得到面板的变化 执行相应的事件
                int level = mysql.checkUser(username, userpassword);
                if(level == 0 ){       // 登录失败
                    JOptionPane.showMessageDialog(null, "用户名或密码出错！", "登录失败", JOptionPane.ERROR_MESSAGE);

                }else{             // 否则登录成功， 在得到用户信息后修改登录时间，再根据权限做出相应的功能
                    user = mysql.getUserInfo(username);  // 通过查找数据库获得该用户所有信息
                    mysql.updateLastLoginTime(username);  // 修改 “lastLogin” 为当前时间
                    tempUid = username;

                    jm =  this.getRootPane().getJMenuBar();//用getRootPane()获取次窗体的rootpane对象
                           //rootpane是这个软件的最顶层它可以获得所有的组件

                    jLoginPanel.setVisible(false);  //    将登陆面板隐藏
                    jLoginerInfoPanel.setVisible(true);
                    jLoginerInfoPanel.updateUI();

                  switch (level){
                     case 1:        //员工管理员
                          enableYourMenu(1);
                          break;

                     case 2:          //仓库管理员
                         enableYourMenu(2);
                         break;

                     case 3:          //进货人员
                         enableYourMenu(3);
                         break;

                     case 4:          //出货人员
                         enableYourMenu(4);
                         break;

                     case 5:          //无权人员
                         enableYourMenu();
                         break;

                     default: ;
                 }

                }

             }catch(Exception e ){
             }

            
        }


    }
    


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jAutoLoginBox;
    private javax.swing.JButton jCancelButton;
    private javax.swing.JTextField jCheckCodeTextField;
    private javax.swing.JLabel jGetAddressLabel;
    private javax.swing.JLabel jGetEmailLabel;
    private javax.swing.JLabel jGetLastLoginLable;
    private javax.swing.JLabel jGetLevelLabel;
    private javax.swing.JLabel jGetTelLabel;
    private javax.swing.JLabel jGetUserNameLabel;
    private javax.swing.JLabel jImageLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JButton jLoginButton;
    private javax.swing.JPanel jLoginPanel;
    private javax.swing.JPanel jLoginerInfoPanel;
    private javax.swing.JCheckBox jSaveUserBox;
    private javax.swing.JTextField jUserNameTextField;
    private javax.swing.JPasswordField jUserPasswordField;
    // End of variables declaration//GEN-END:variables

    private int saveuid ; // 用户名
    private int savepassword ;  // 密码
    private String code;    // 验证码
    private User user;  // 用户信息
    private JMenuBar jm ;  // 主菜单栏
    public static String tempUid;

    private java.awt.image.BufferedImage image;


    // 显示验证码
    private void showCheckImage(){

        others.Image image = new others.Image();
        jImageLabel.setIcon( new ImageIcon(image.getImage()) );
        this.code = image.getCode() ;
   
    }

    // 显示你要的 menu 
    private void enableYourMenu(int ... i){
         jm.getMenu(1).setEnabled(false) ;
         jm.getMenu(2).setEnabled(false) ;
         jm.getMenu(3).setEnabled(false) ;
         jm.getMenu(4).setEnabled(false) ;
         jm.getMenu(5).setEnabled(true);
         for(int j = 0; j < i.length; j++){
            jm.getMenu(i[j]).setEnabled(true);
         }
    }

}
